package com.jacarrichan.demo.dipper.handler;

import com.alibaba.fastjson.JSONObject;
import com.pactera.dipper.core.IDipperHandler;
import com.pactera.dipper.core.Message;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;


/**
 * 发起支付接口，生成url签名<br/>
 * 以cmblife://pay?开通，对所有参数排序，将值urlencode <br/>
 * sign(cmblife://pay?a=urlencode(1)&b=urlencode(2))
 */
public class ReqPaySignHandler implements IDipperHandler<Message> {
    static final Logger LOGGER = LoggerFactory.getLogger(ReqPaySignHandler.class);

    private final String EXTRA_KEY = "extra";
    private final String PAY_SERVER = "cmblife://pay?";//

    private String keyStr;// 3des密钥


    public ReqPaySignHandler() throws Exception {

    }


    public void setKeyStr(String keyStr) {
        this.keyStr = keyStr;
    }


    @Override
    public Message handle(Message m) throws Exception {
        String charset = m.getCharset();
        String payloadString = new String((byte[]) m.getTarget().getBodys(), charset);
        //  删除签名逻辑
        HashMap<String, Object> map = new HashMap<>();
        map.put("reqPayUrl", payloadString);
        m.getTarget().setBody(map);
        return m;
    }

}
